package com.xiaoluo.web.form;

import java.util.HashMap;
import java.util.Map;

/**
 * Project : XL-CD
 * Package : com.xiaoluo.web.form
 * Created by Willian.
 * Date  : 2016/2/2 15:11.
 *
 * Kubernetes pod/service/replicacontroller 综合类
 * 服务名称、端口
 * Pod状态
 * ReplicaController 实例数
 */
public class KubeServiceForm implements Comparable {

    private String namespace;

    private String name;

    private Integer port;

    private Integer targetPort;

    private Integer nodePort;

    private String protocol;

    private String clusterIp;

    private String hostIp;

    private String podIp;

    private Integer replicas;

    private String selector;

    private String ready;

    private String status;

    private String restartPolicy;

    private String images;

    private String version;

    private String uuid;

    private String msg;

    private String type;

    private Map<String,String> podIpMap = new HashMap<String, String>();

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getType() {

        if(selector != null){
            if(selector.indexOf("k8s-app")>0){
                return "SYSTEM";
            }else if(selector.indexOf("app")>0){
                return "APP";
            }else {
                return "OTH";
            }
        }
        return "OTH";
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getHostIp() {
        return hostIp;
    }

    public void setHostIp(String hostIp) {
        this.hostIp = hostIp;
    }

    public String getPodIp() {
        return podIp;
    }

    public void setPodIp(String podIp) {
        if(this.podIp != null && !"".equals(this.podIp)){
            if(podIpMap.get(podIp) == null) {
                this.podIp = this.podIp + "<br/>" + podIp;
            }
        }else {
            this.podIp = podIp;
        }
        podIpMap.put(podIp,podIp);
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getVersion() {

        if(images != null && images.lastIndexOf(":")>0){
            return images.substring(images.lastIndexOf(":")+1);
        }
        return images;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Integer getTargetPort() {
        return targetPort;
    }

    public void setTargetPort(Integer targetPort) {
        this.targetPort = targetPort;
    }

    public Integer getNodePort() {
        return nodePort;
    }

    public void setNodePort(Integer nodePort) {
        this.nodePort = nodePort;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String getClusterIp() {
        return clusterIp;
    }

    public void setClusterIp(String clusterIp) {
        this.clusterIp = clusterIp;
    }

    public Integer getReplicas() {
        return replicas;
    }

    public void setReplicas(Integer replicas) {
        this.replicas = replicas;
    }

    public String getSelector() {
        return selector;
    }

    public void setSelector(String selector) {
        this.selector = selector;
    }

    public String getReady() {
        return ready;
    }

    public void setReady(String ready) {
        this.ready = ready;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getRestartPolicy() {
        return restartPolicy;
    }

    public void setRestartPolicy(String restartPolicy) {
        this.restartPolicy = restartPolicy;
    }

    public String getImages() {
        return images;
    }

    public void setImages(String images) {
        this.images = images;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public int compareTo(Object o) {
        KubeServiceForm temp = (KubeServiceForm) o;
        return this.getType().compareTo(temp.getType());
    }
}
